package chapter06

/**
 *
 * @author cdhuangchao3
 * @date 2023/6/9 5:53 PM
 */
object Test06_ConstructorParams {
  def main(args: Array[String]): Unit = {
    val student2 = new Student2
    student2.name = "zs"
    student2.age = 20
    println(s"student2: name= ${student2.name} age= ${student2.age}")

    val student3 = new Student3("zsf", 21)
    println(s"student3: name= ${student3.name} age= ${student3.age}")

    val student4 = new Student4("zsf", 21)
    student4.printInfo()
//    println(s"student3: name= ${student4.name} age= ${student4.age}") // error
  }
}

// 定义类
// 无参构造器
class Student2 {
  // 单独定义属性
  var name: String = _
  var age: Int = _

}

//
class Student3(var name: String, var age: Int)

// 主构造器参数无修饰
class Student4(name: String, age: Int) {
  def printInfo(): Unit = {
    println(s"student4: name= ${name} age= ${age}")
  }
}

class Student5(val name: String, val age: Int)